import { IPSDEField } from '../defield/ipsdefield';
import { IPSDERIndex } from './ipsderindex';
import { IPSDERIndexDEFieldMap } from './ipsderindex-defield-map';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDERIndexDEFieldMapImpl extends PSModelObjectImpl implements IPSDERIndexDEFieldMap {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  protected majorpsdefield: IPSDEField | null = null;

  getMajorPSDEField(): IPSDEField | null {
    if (this.majorpsdefield != null) return this.majorpsdefield;
    const value = this.M.getMajorPSDEField;
    if (value == null) {
      return null;
    }
    const ipsderindex = this.getParentPSModelObject('dataentity.der.IPSDERIndex') as IPSDERIndex;
    if (ipsderindex != null) {
      this.majorpsdefield = ipsderindex.getMajorPSDataEntityMust().findPSDEField(value);
    }
    return this.majorpsdefield;
  }

  get majorPSDEField(): IPSDEField | null {
    return this.getMajorPSDEField();
  }

  getMajorPSDEFieldMust(): IPSDEField {
    const value = this.getMajorPSDEField();
    if (value == null) {
      throw new Error('未指定主实体属性');
    }
    return value;
  }

  get memo(): string {
    return this.M.memo;
  }

  protected minorpsdefield: IPSDEField | null = null;

  getMinorPSDEField(): IPSDEField | null {
    if (this.minorpsdefield != null) return this.minorpsdefield;
    const value = this.M.getMinorPSDEField;
    if (value == null) {
      return null;
    }
    const ipsderindex = this.getParentPSModelObject('dataentity.der.IPSDERIndex') as IPSDERIndex;
    if (ipsderindex != null) {
      this.minorpsdefield = ipsderindex.getMinorPSDataEntityMust().findPSDEField(value);
    }
    return this.minorpsdefield;
  }

  get minorPSDEField(): IPSDEField | null {
    return this.getMinorPSDEField();
  }

  getMinorPSDEFieldMust(): IPSDEField {
    const value = this.getMinorPSDEField();
    if (value == null) {
      throw new Error('未指定从实体属性');
    }
    return value;
  }

  get name(): string {
    return this.M.name;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDERIndexDEFieldMapImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.der.IPSDERIndexDEFieldMap') return true;
    return super.instanceof(cls);
  }
}
